import svar
import cv2
import numpy as np
import time


osdk=svar.load('svar_osdk')

env=osdk.LinuxSetup(True)
vehicle = env.getVehicle()

def callback_file(ret_code):
  print(ret_code)
  
def callback_file_list(file_list):
  print(file_list.media)
  if len(file_list.media) == 0:
    return
  
vehicle.cameraManager.setModeSync(osdk.PAYLOAD_INDEX_0,osdk.MEDIA_DOWNLOAD,2)
vehicle.cameraManager.obtainDownloadRightSync(osdk.PAYLOAD_INDEX_0,True,2)

file_list=vehicle.cameraManager.reqFileList(osdk.PAYLOAD_INDEX_0)

media=file_list.media
print(media)

if len(media) == 0:
  exit(0)

for m in media:
  print("reqesting file",m.fileName)
  ret=vehicle.cameraManager.reqFileData(osdk.PAYLOAD_INDEX_0,m.fileIndex,m.fileName)
  print("reqest finished with code:",ret)

  osdk.ErrorCode.printErrorCodeMsg(ret)

